﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PixelWarfare
{
    /// <summary>
    /// Menu works by inheriting and adding items in the child by using all the addItem()
    /// methods. If you wanna add extra implementation for input or drawing simply override
    /// the necessary method and call the base method.
    /// </summary>
    class Menu : Screen
    {
        #region Fields

        private List<IMenuItem> items;

        #endregion

        #region Constructors

        /// <summary>
        /// Protected constructor that only inherting classes can use.
        /// </summary>
        protected Menu()
            : base()
        {
            items = new List<IMenuItem>();
        }

        #endregion

        #region Protected Methods

        /// <summary>
        /// Add a selection item to the menu with the given parameters.
        /// </summary>
        protected void AddSelectionItem(string text, int x, int y, Font font, Color onColor, Color offColor, OnClick clicked)
        {
            items.Add(new SelectionMenuItem(text, x, y, font, onColor, offColor, clicked));
        }

        /// <summary>
        /// Add an option item to the menu with the given parameters.
        /// </summary>
        protected void AddOptionItem(string text, string[] options, int x, int y, Font font, Color onColor, Color offColor, OnClick clicked)
        {
            items.Add(new OptionMenuItem(text, options, x, y, font, onColor, offColor, clicked));
        }

        /// <summary>
        /// Add a picture item to the menu with the given parameters.
        /// </summary>
        protected void AddPictureItem(Bitmap img, int x, int y, OnClick clicked)
        {
            items.Add(new PictureMenuItem(img, x, y, clicked));
        }

        /// <summary>
        /// Add a picture item to the menu with the given parameters.
        /// </summary>
        protected void AddBlobItem(Bitmap img, int x, int y, Point[] points, int speed, OnClick clicked)
        {
            items.Add(new BlobMenuItem(img, x, y, points, speed, clicked));
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Draw all of its menu items.
        /// </summary>
        /// <param name="g">Graphics to be drawn on.</param>
        public override void Draw(Graphics g)
        {
            foreach (IMenuItem i in items)
            {
                i.Draw(g);
            }
        }

        /// <summary>
        /// Pass through the mouse click events to all of its items.
        /// </summary>
        /// <param name="x">X coordinate of the mouse click.</param>
        /// <param name="y">Y coordinate of the mouse click.</param>
        public override void MousePress(int x, int y)
        {
            foreach (IMenuItem i in items)
            {
                i.MousePress(x, y);
            }
        }

        /// <summary>
        /// Pass through the mouse move events to all of its items.
        /// </summary>
        /// <param name="x">X coordinate of the mouse.</param>
        /// <param name="y">Y coordinate of the mouse.</param>
        public override void MouseMove(int x, int y)
        {
            foreach (IMenuItem i in items)
            {
                i.MouseMove(x, y);
            }
        }

        /// <summary>
        /// Update all the items.
        /// </summary>
        public override void Update()
        {
            foreach (IMenuItem i in items)
            {
                i.Update();
            }
        }

        /// <summary>
        /// Menus dont have anything to update constanly and dont have any
        /// events tied to these inputs mediums.
        /// 
        /// However when inherited they can be overridden.
        /// </summary>
        #region Unneeded Methods

        public override void MouseRelease(int x, int y) { }

        public override void KeyPress(System.Windows.Forms.Keys key) { }

        public override void KeyRelease(System.Windows.Forms.Keys key) { }

        #endregion      

        #endregion
    }
}
